package com.hfkh;

/**
 * @Author MDD
 * @Description
 * @Version
 * @Date
 **/
public class StudentService {



        //学员集合
        //Student[] students = new Student[5];

        Student[] students = null;




        //students[0] = null
        public StudentService(){
        /*students[0] = new Student(1,"Allen",60);
        students[1] = new Student(2,"Tom",70);
        students[2] = new Student(3,"Alice",80);
        students[3] = new Student(4,"Sam",90);
        students[4] = new Student(5,"Rose",98);*/

       /* students = new Student[]{
                new Student(1,"Allen",60),
                new Student(2,"Tom",70),
                new Student(3,"Alice",80),
                new Student(4,"Sam",90),
                new Student(5,"Rose",98)
        };*/


            Student allen = new Student(1,"Allen",10);
            Student tom = new Student(2,"Tom",20);
            Student alice = new Student(3,"Alice",30);
            Student sam = new Student(4,"Sam",40);
            Student rose = new Student(5,"Rose",50);

            students = new Student[]{
                    allen,
                    tom,
                    alice,
                    sam,
                    null
            };
        }


        public void changeScore(Student[] abc){ //students = null  对象数组入参
            if(abc == null){
                throw new IllegalArgumentException("参数不能为null");
            }
            for (int i = 0; i < abc.length; i++) {
                if(abc[i] != null && abc[i].score < 60){
                    abc[i].score += 2;
                }
            }
        }
        public static void main(String[] args) {
            StudentService ss = new StudentService();
            System.out.println("加分之前，遍历学员集合");
            System.out.println("学号\t姓名\t成绩");
            for (Student stu : ss.students) {
                if(stu != null) {
                    System.out.println(stu.id + "\t" + stu.name + "\t" + stu.score);
                }
            }
            System.out.println("---------------------传引用（内存地址）-----------------------------------");
            //重要代码
            ss.changeScore(ss.students);
            System.out.println("加分之后，遍历学员集合");
            System.out.println("学号\t姓名\t成绩");
            for (Student stu : ss.students) {
                if(stu != null) {
                    System.out.println(stu.id + "\t" + stu.name + "\t" + stu.score);
                }
            }
        }
}
